package com.example.controller;

import com.example.entity.constants.Constants;
import com.example.entity.dto.TokenUserInfoDTO;
import com.example.entity.vo.ResponseVO;;
import com.example.enums.ResponseCodeEnum;
import com.example.redis.RedisUtils;;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

public class ABaseController {
    protected static final String STATUS_SUCCESS = "success";
    protected static final String STATUS_ERROR = "error";
    @Resource
    private RedisUtils redisUtils;
    protected <T> ResponseVO getSuccessResponseVO(T t) {
        ResponseVO<T> responseVO = new ResponseVO<>();
        responseVO.setStatus(STATUS_SUCCESS);
        responseVO.setCode(ResponseCodeEnum.CODE_200.getCode());
        responseVO.setInfo(ResponseCodeEnum.CODE_200.getMsg());
        responseVO.setDate(t);
        return responseVO;
    }
    protected TokenUserInfoDTO getTokenUserInfo(HttpServletRequest request) {
        String token = request.getHeader("token");
        TokenUserInfoDTO tokenUserInfoDTO = (TokenUserInfoDTO) redisUtils.get(Constants.REDIS_KEY_WS_TOKEN + token);
        return tokenUserInfoDTO;
    }
}
